#include "lom-class-manager.hh"
#include "lom-errors.hh"

using namespace licada;

namespace lom
{
    
    LomClassManager::~LomClassManager() { internal_reset();}
    
    void LomClassManager::addClass( const LomClass& cls )
    {
	TNameToClassMap::iterator find = classMap.find( cls.getName() );
	if ( find != classMap.end() )
	    throw DuplicateClassName( cls.getName() );
	find = classMap.insert( std::make_pair( cls.getName(), cls ) ).first;
	sendClassCreated( find->second );
    }
    
    const LomClass* LomClassManager::getClass( const TNameStr& name )
    {
	TNameToClassMap::iterator find = classMap.find( name );
	if ( find == classMap.end() )
	    throw MissingClassName( name );
	return &find->second;
    }
    const TNameToClassMap& LomClassManager::getClassMap() { return classMap; }

    void LomClassManager::reset()
    {
	internal_reset();
    }
    void LomClassManager::internal_reset()
    {
	classMap.clear();
    }
}
